package cn.liwq.demo.java.raw.proxy.handler;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * <p>Project: demo-common </p>
 * 
 * <p>Function:  </p>
 * 
 * <p>Description:  </p>
 * 
 * <p>Copyright: Copyright(c) 2018 Ucarinc </p>
 * 
 * <p>Company: Ucarinc </p>
 * 
 * @author weiqiang.li@ucarinc.com
 * 
 * @date 2018-08-15 19:49:11
 * 
 * @version 1.0
 */
public class LoggerHanlder implements MethodInterceptor {

    @Override
    public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
        System.out.println("logger: into method=" + method.getName());
        long start = System.currentTimeMillis();
        Object result = proxy.invokeSuper(obj, args);
        long waste = System.currentTimeMillis() - start;
        System.out.printf("logger: leave method=%s, waste time=%d(ms)", method.getName(), waste);
        return result;
    }
}
